package com.lyc.service.impl;

import com.lyc.dao.UserMapper;
import com.lyc.entity.User;
import com.lyc.service.IUserService;
import com.lyc.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional
    public void register(User user) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        user.setPassword(MD5Util.encryptPassword(user.getPassword(),user.getUsername()));
        userMapper.insertSelective(user);
    }

    @Override
    public User checkName(String username) {
        return userMapper.selectByUsername(username);
    }
}
